fix b2sum, md5sum and hashsum regressions#8760
fix b2sum, md5sum and hashsum regressions#8760sylvestre wants to merge 2 commits intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
| BitsRequiredForShake256, | ||
| #[error("--bits required for SHA2")] | ||
| BitsRequiredForSha2, | ||
| #[error("Invalid output size for SHA2 (expected 224, 256, 384, or 512), got {0}")] |
There was a problem hiding this comment.
i noticed that we aren't translating this file, i will fix it next
|
GNU testsuite comparison: |
CodSpeed Performance ReportMerging #8760 will not alter performanceComparing Summary
Footnotes
|
|
GNU testsuite comparison: |
| .arg("lorem_ipsum.txt") | ||
| .fails_with_code(1) | ||
| .no_stdout() | ||
| .stderr_contains("--bits required for SHA2"); |
There was a problem hiding this comment.
The expected error message is incorrect as there is no --bits option.
| .stderr_contains("--bits required for SHA2"); | |
| .stderr_contains("--length required for SHA2"); |
GNU cksum itself shows the following error:
cksum: --algorithm=sha2 requires specifying --length 224, 256, 384, or 512
| } | ||
|
|
||
| #[test] | ||
| fn test_sha2_with_length_224() { |
There was a problem hiding this comment.
It might make sense to combine the test_sha2_with_length_xxx tests into a single test function that loops over the valid lengths.
There was a problem hiding this comment.
Maybe we could leverage rstest here. It offers parametrized tests (the macro generates all the testcases independently). See https://github.com/la10736/rstest?tab=readme-ov-file#parametrize
| // Should contain base64 characters and SHA256 label | ||
| assert!(result.contains("SHA256")); | ||
| // Base64 should end with = or == or contain +/ | ||
| assert!(result.contains('=') || result.contains('+') || result.contains('/')); |
There was a problem hiding this comment.
I would use a single assert and check for the correct output. The second assert is currently true independent of whether the output is base64 because result.contains('=') matches the delimiter between hash name and hash. And the "or" conditions are not necessary because you know the expected output.
| #[error("--bits required for SHA2")] | ||
| BitsRequiredForSha2, | ||
| #[error("Invalid output size for SHA2 (expected 224, 256, 384, or 512), got {0}")] | ||
| InvalidSha2Length(usize), |
There was a problem hiding this comment.
For SHA3 we use InvalidOutputSizeForSha3, and so for consistency reasons I would use a similar name:
| InvalidSha2Length(usize), | |
| InvalidOutputSizeForSha2(usize), |
| let error_key = format!("{}-error-invalid-length", utility_name); | ||
| let max_key = format!("{}-error-max-digest-length", utility_name); | ||
| show_error!( | ||
| "{}", | ||
| translate!(&error_key, "length" => DisplayQuotable::quote(length_str)) | ||
| ); | ||
| Err(io::Error::new( | ||
| io::ErrorKind::InvalidInput, | ||
| translate!(&max_key, "algorithm" => "BLAKE2b", "max_bits" => 512), | ||
| ) | ||
| .into()) |
There was a problem hiding this comment.
This part is almost a duplicate of the ones above, there might be a way to factorize it with closures ?
|
|
||
| /// Validate BLAKE2b length with Fluent error messages | ||
| /// This function is used by utilities that need localized error messages | ||
| pub fn validate_blake2b_length(length_str: &str, utility_name: &str) -> UResult<Option<usize>> { |
There was a problem hiding this comment.
I'm struggling with this function as it duplicates the code of validate_blake2b_length_str and calculate_blake2b_length. And thus it makes it easy to introduce sync issues in the future.
| pub const ALGORITHM_OPTIONS_SM3: &str = "sm3"; | ||
| pub const ALGORITHM_OPTIONS_SHAKE128: &str = "shake128"; | ||
| pub const ALGORITHM_OPTIONS_SHAKE256: &str = "shake256"; | ||
| pub const ALGORITHM_OPTIONS_SHA2: &str = "sha2"; |
There was a problem hiding this comment.
A detail: I would move this line up to line 39, so that it is between the consts for SHA1 and SHA3.
|
@sylvestre I guess this PR needs a rework as |
|
@sylvestre is this PR still relevant? In the meantime all failing |
|
probably not :) |
No description provided.